<?php
namespace AuctionCore\Account;
use AuctionCore\System\AuctionException;

class FoursAdmin 
{	
    /**
     * 构造,初始化
     * @param    String $user_name    后台登录用户名
     * @return   void
     */
    protected $user_name;

	public function __construct($user_name) {
		$this->user_name = $user_name;
    }


    public function check_name(){
    	$prefix = C("DB_PREFIX");
    	$where['u.user_name'] = array('eq',$this->user_name);
    	$where['g.group_id'] = array('gt','3');
    	$info = M('user')->alias('u')
    	->join("JOIN {$prefix}auth_group_access as g ON g.uid = u.uid")
    	->where($where)->find();
    	// echo M()->getLastSql();
    	return $info;
    }

    //登陆成功后将错误次数清零
    public static function clearcount($ip){
        $redis = new \AuctionCore\Common\PhpRedis(0);
        $keyArr = [
            'ip'=>$ip,
        ];
        $keyName = getRedisKeyByCode('REDIS_KEY','100007',$keyArr);
        //$key = "4s_logined_".$ip;
        $ok = $redis->del($keyName);
        return $ok;
    }

    // 验证验证码
    public function chkcode($code)
    {
        $verify = new \Think\Verify();
        return $verify->check($code);
    }

    //获取redis存储登陆错误次数
    public static function getcount($ip){
        $redis = new \AuctionCore\Common\PhpRedis(0);
        //$key = "4s_logined_".$ip;
        $keyArr = [
            'ip'=>$ip,
        ];
        $key = getRedisKeyByCode('REDIS_KEY','100007',$keyArr);
        if ($redis->get($key)) {
            $count = $redis->get($key);
        }else{
            $redis->set($key,0,7200);
            $count = $redis->get($key);
        }
        return $count;
    }
    //设置redis存储登陆错误次数
    public static function setcount($ip){
        $redis = new \AuctionCore\Common\PhpRedis(0);
        //$key = "4s_logined_".$ip;
        $keyArr = [
            'ip'=>$ip,
        ];
        $key = getRedisKeyByCode('REDIS_KEY','100007',$keyArr);
        $redis->incr($key);
        return $count = $redis->get($key);
    }
}